package com.yztc.orangeentertainment.ui.main.findfragment.findadapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yztc.orangeentertainment.R;
import com.yztc.orangeentertainment.bean.findbean.FindActivityBean;
import com.yztc.orangeentertainment.ui.main.findfragment.findmain.FindActionActivity;

import java.util.List;

/**
 * Created by My on 2016/10/7.
 */
public class FindActivityAdapter extends RecyclerView.Adapter<FindActivityAdapter
        .ActivityViewHolder> {
    private Context context;
    private List<FindActivityBean> list;

    public FindActivityAdapter(Context context, List<FindActivityBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public ActivityViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ActivityViewHolder holder = new ActivityViewHolder(LayoutInflater.from(context).inflate(R
                .layout.find_activity, null));
        return holder;
    }

    @Override
    public void onBindViewHolder(ActivityViewHolder holder, final int position) {
        holder.tv_title.setText(list.get(position).getTitle());
        holder.tv_sub.setText(list.get(position).getSub());
        Glide.with(context).load(list.get(position).getPic()).into(holder.iv);
        holder.findAction.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, FindActionActivity.class);
                String str = list.get(position).getUrlroute();
                String act = str.substring(str.lastIndexOf("a"), str.lastIndexOf("."));
                intent.putExtra("act", act);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ActivityViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_title, tv_sub;
        private ImageView iv;
        private LinearLayout findAction;

        public ActivityViewHolder(View itemView) {
            super(itemView);
            tv_title = (TextView) itemView.findViewById(R.id.findactivity_title);
            tv_sub = (TextView) itemView.findViewById(R.id.findactivity_sub);
            iv = (ImageView) itemView.findViewById(R.id.findactivity_iv);
            findAction = (LinearLayout) itemView.findViewById(R.id.findaction);
        }
    }
}
